$(function(){
	App.code = 'soagov';
	App.ctx = '/' + App.code;
	App.page = '#';
	App.scheme = 'basic';
	App.main = $('#body');
	
	var page = $('body'), hdD = page.children('.headBar'), bdD = $('#body');

	App.go = function(to) {
		App.page = to;
		if (window.location.hash != to) {
			window.location.hash = to;
		}
		var i = to.indexOf('?');
		if (i > 0) {
			to = to.substr(0, i);
		}
		switch (to) {
		case '':
		case '#':
		case 'home':
			App.show({
				ctx: 'soagov',
				action: 'home'
			}, $.noop, bdD);
			break;
		case '#flow/edit':
			App.show({
				ctx: 'soagov',
				action: 'flowEdit'
			}, $.noop, bdD);
			break;
		}
	}

	function adjust(){
		var de = document.documentElement
			, ch = de.clientHeight, cw = de.clientWidth;
		hdD.width();
		bdD.width(cw).height(ch - hdD.height());
	}
	$(window).resize(adjust);
	adjust();

	if (window.history && window.history.pushState) {
		window.onpopstate = function() {
			if (App.page != window.location.hash) {
				App.go(window.location.hash);
			}
		}
	}
	
	var w = mac.wait('Please wait...');
	if (App.page != window.location.hash) {
		App.go(window.location.hash);
	}
	if (w) {
		w.close();
	}
});
